package com.topnav.mc.admin.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.js.lib.utils.JsonUtil;
import com.topnav.mc.entity.base.BaseEntity;
import com.topnav.mc.schedule.task.QuartzTask;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * Quartz调度任务，保存到数据库中
 */
@Data
@Accessors(chain=true)
@TableName("mc_quartz_job")
public class GbQuartzJob extends BaseEntity {
    private String jobDesc;
    private String jobName;
    private String jobGroupName;
    private String triggerName;
    private String triggerGroupName;
    private String jobClass;
    private String cron;
    /** 是否禁止 1 启用，0停止*/
    private Integer status;

    /** Map 对象，数据保存为 JSON字符串*/
    private String params;



    public QuartzTask toTask(){
        QuartzTask task = new QuartzTask()
                .setJobName(this.getJobName())
                .setJobGroupName(this.getJobGroupName())
                .setTriggerName(this.getTriggerName())
                .setTriggerGroupName(this.getTriggerGroupName())
                .setCron(this.getCron()) // 每10秒触发一次
                .setJobClass(this.getJobClass());
        if (!StringUtils.isEmpty(this.params)){
            Map<String, Object> map = JsonUtil.fromJson(params,Map.class);
            task.setParams(map);
        }

        return task;
    }

}
